The Video Card and Screen
Your application can declare colors in RGB space, but what the user finally
sees depends on the characteristics of the actual video card and screen. Screens
may display color or black and white, and have indexed pixels of 2-bit, 4-bit,
or 8-bit bit depths, or direct pixels of 16-bit or 32-bit depths.
Preparing an image for display in the original QuickDraw means preparing a bitmap, which specifies the memory arrangement of the bits that describe
whether each pixel on a screen is to be on or off. Specifying on or off takes just
1 bit. You can describe the state of 8 pixels in a single byte. Entire
black-and-white screen images can be stored in what is now considered a
modest amount of memory.
Preparing a color or gray-scale image requires a pixel map, where more
than one bit may be assigned to determine the color of each screen pixel. Two
bits per pixel provide indexes into a table of four colors, but if two colors are
black and white, only two other hues can be shown. A four-index color table
might contain the following entries.
Index Color
00 White (turn all three RGB phosphors full on)
01 Gray (turn all three on halfway)
10 Pale blue for highlighting (turn all three on, but use more
blue)
11 Black (turn them all off)
If a 2-bit memory space representing a pixel had a value of 00, the resulting
screen pixel would be white. The sequence 10 10 10 10 would use the third
entry in the table to generate a series of pale blue pixels on the screen.
Four bits can provide indexes into a table of 16 colors, a number sufficient
for many straight-forward graphics purposes, such as charts, presentations,
or displaying flags of the nations.
Using a byte (8 bits) for each pixel, 256 colors can be displayed, which for
many images is enough to produce near-photographic quality. The problem is
that the colors good for one near-photographic image may not be good for
an other. Rembrandt's browns and umbers don't do much for a still from The Wizard of Oz. To solve this problem, the Macintosh II video card uses a variable
color table (rather than a fixed one). You can display Rembrandt with one set
of 256 colors, then reload the table for another image.
The main reason for using variable color tables is that a relatively small
index value is sufficient to specify any one color out of a palette of millions.
You need less RAM to store an image and less time to move it around than if you
use large RGB values directly. An extra benefit is color table animation, by
which your application can change colors on the screen without actually
reassigning pixel values. (By changing the colors of the 256 entries of an
8-bit table, you change all the screen's colors-without any changes in screen
memory.) Drawbacks are that since only 256 colors can appear on the screen
at once, windows must compete for colors, and pairing an RGB request to the
closest actual color in the table requires the complex inverse-table matching
Video boards that implement direct pixels, in which the pixel value specifies
an RGB color rather than an index into a table of colors, eliminate the
competition for limited table spaces and remove the need for color table
matching. The direct pixel system is simpler. The cost is larger amounts of
RAM needed to hold the larger pixel values; the benefit-thousands and even
millions of colors on the screen at once-is worth the cost for many
applications, some of which would not exist without such a capability.
The Major Data Structures
Understanding Macintosh graphics is easier with some knowledge of the data
structures that hold the information and define the graphics environment.
QuickDraw supplies routines for querying and altering the fields of these data structures; you should not alter them directly. (If you have existing
programs that change fields directly, see Color QuickDraw for a description of routines that you can use to notify QuickDraw of such changes.) The smallest place to begin is the RGB color record, which holds a single
color.